package com.yunsc.order.sevice.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yunsc.common.properties.MinioProperties;
import com.yunsc.common.utils.PageResult;
import com.yunsc.order.dao.YunscOrderExportDao;
import com.yunsc.order.entity.YunscOrderExportEntity;
import com.yunsc.order.sevice.YunscOrderExportService;
import com.yunsc.store.dto.QueryPageDTO;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;


@Service("yunscOrderExportService")
public class YunscOrderExportServiceImpl extends ServiceImpl<YunscOrderExportDao, YunscOrderExportEntity> implements YunscOrderExportService {

    @Resource
    private MinioProperties minioProperties;

    @Override
    public PageResult<YunscOrderExportEntity> queryOrderExportList(QueryPageDTO params, Integer storeId) {
        LambdaQueryWrapper<YunscOrderExportEntity> lqw = new LambdaQueryWrapper<>();
        lqw.eq(YunscOrderExportEntity::getStoreId, storeId);
        lqw.orderByDesc(YunscOrderExportEntity::getCreateTime);
        Page<YunscOrderExportEntity> pageResult = this.page(new Page<>(params.getPage(), params.getPageSize()), lqw);
        pageResult.getRecords().forEach(item -> {
            item.setDownloadUrl(minioProperties.getEndpoint() + "/" + item.getFilePath());
        });
        return PageResult.formatPageResult(pageResult.getRecords(), params.getPage(), params.getPageSize(), pageResult.getTotal());
    }
}